package 贪心算法.加油站;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2023/2/3 14:52
 * @description:
 * @version:
 */
public class Solution {
    public static void main(String[] args) {
        File file = new File("D:\\tmp\\a");
        file.mkdir();
        if (file.exists()){
            String[] list = file.list();
            for (int i = 0; i < list.length; i++) {
                System.out.println(list[i]);
            }
            System.out.println("------------------------------------------");
            System.out.println(Arrays.toString(list));
        }else {
            System.out.println("文件不存在");
        }

    }

    public static int canCompleteCircuit(int[] gas, int[] cost) {
        int n = gas.length;
        int i = 0;
        while (i < n) {
            int sumOfGas = 0, sumOfCost = 0;
            int cnt = 0;
            while (cnt < n) {
                //加油站是环形的
                int j = (i + cnt) % n;
                sumOfGas += gas[j];
                sumOfCost += cost[j];
                if (sumOfCost > sumOfGas) {
                    break;
                }
                cnt++;
            }
            if (cnt == n) {
                return i;
            } else {
                i = i + cnt + 1;
            }
        }
        return -1;
    }
}
